/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package multiface.promonet.jpa;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author diego
 */
@Entity
@Table(name = "referente")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Referente.findAll", query = "SELECT r FROM Referente r"),
    @NamedQuery(name = "Referente.findByUtente", query = "SELECT r FROM Referente r WHERE r.referentePK.utente = :utente"),
    @NamedQuery(name = "Referente.findByReferente", query = "SELECT r FROM Referente r WHERE r.referentePK.referente = :referente"),
    @NamedQuery(name = "Referente.findByZona", query = "SELECT r FROM Referente r WHERE r.zona = :zona")})
public class Referente implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ReferentePK referentePK;
    @Column(name = "zona")
    private String zona;
    @JoinColumn(name = "referente", referencedColumnName = "idutente", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Utente utente1;
    @JoinColumn(name = "utente", referencedColumnName = "idutente", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Utente utente2;
    @JoinColumn(name = "promozione", referencedColumnName = "idpromozione")
    @ManyToOne
    private Promozione promozione;

    public Referente() {
    }

    public Referente(ReferentePK referentePK) {
        this.referentePK = referentePK;
    }

    public Referente(int utente, int referente) {
        this.referentePK = new ReferentePK(utente, referente);
    }

    public ReferentePK getReferentePK() {
        return referentePK;
    }

    public void setReferentePK(ReferentePK referentePK) {
        this.referentePK = referentePK;
    }

    public String getZona() {
        return zona;
    }

    public void setZona(String zona) {
        this.zona = zona;
    }

    public Utente getUtente1() {
        return utente1;
    }

    public void setUtente1(Utente utente1) {
        this.utente1 = utente1;
    }

    public Utente getUtente2() {
        return utente2;
    }

    public void setUtente2(Utente utente2) {
        this.utente2 = utente2;
    }

    public Promozione getPromozione() {
        return promozione;
    }

    public void setPromozione(Promozione promozione) {
        this.promozione = promozione;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (referentePK != null ? referentePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Referente)) {
            return false;
        }
        Referente other = (Referente) object;
        if ((this.referentePK == null && other.referentePK != null) || (this.referentePK != null && !this.referentePK.equals(other.referentePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "multiface.promonet.jpa.Referente[ referentePK=" + referentePK + " ]";
    }
    
}
